package com.bristua.common.biz;

import com.bristua.common.dao.TDictionaryMapper;
import com.bristua.common.model.TDictionary;
import com.bristua.common.model.condition.TDictionaryExample;
import com.bristua.common.utils.SequenceUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/4/29.
 */
@Transactional
@Service
public class UpdateReturnScaleBiz {

    private final static String SCALE ="scale";

    @Resource
    private TDictionaryMapper tDictionaryMapper;

    public void updateReturnScale(String scale){
        if(!StringUtils.isEmpty(scale)){
            TDictionaryExample tDictionaryExample = new TDictionaryExample();
            tDictionaryExample.createCriteria().andDictionaryKeyEqualTo(SCALE);
            List<TDictionary> tDictionaries = tDictionaryMapper.selectByExample(tDictionaryExample);
            if(tDictionaries!=null && tDictionaries.size()>0){
                TDictionary tDictionary = tDictionaries.get(0);
                tDictionary.setDictionaryValue(scale);
                tDictionaryMapper.updateByPrimaryKeySelective(tDictionary);
            }else{
                TDictionary tDictionary = new TDictionary();
                tDictionary.setDictionaryValue(scale);
                tDictionary.setDictionaryKey(SCALE);
                tDictionary.setDictionaryId(SequenceUtil.nextId());
                tDictionary.setDictionarySort(1);
                tDictionaryMapper.insert(tDictionary);
            }

        }

    }
}
